#include "Comm.hpp"

int main()
{
    Fifo fifo(Path);//实例化
    //打开文件
    int rfd = open(Path, O_RDONLY);
    if(rfd < 0)
    {
        cout << "open fail, errno: " << errno << " stringerrno: " << strerror(errno) << endl;
        return 1;
    }
    char buffer[1024];
    while(true)
    {
        ssize_t n = read(rfd, buffer, sizeof(buffer)-1);
        if(n > 0)//读取成功
        {
            buffer[n] = 0;
            cout << "message: " <<buffer<<endl;
        }
        else if(n == 0)//读停止 
        {
            cout << "read quit.. " <<endl;
            break;
        }
        else //读失败
        {
            cout << "read fail, errno: " << errno << " stringerrno: " << strerror(errno) << endl;
            break;
        }
    }
    close(rfd);//关闭文件
    return 0;
}